import axios from './axios.js'


// 获取食谱
export const getAllCooks = async (id) => {
  return await axios.get('/cook/getAllCooks', {
    params: { id }
  })
}

// 登录接口
export const userLogin = async (params) => {
  return await axios.post('/user/login', params)
}

// 注册接口

export const userRegister = async (params) => {
  return await axios.post('/user/userRegister', params)
}



// 根据菜名生成步骤
export const generateStep = async (cookName) => {
  return await axios.get('/cook/generateStep', {
    params: { cookName }
  })
}

// 添加生成的菜谱
export const addCook = async (params) => {
  return await axios.post('/cook/addCook', params)
}


// 根据id获取一道菜
export const getCookById = async (id) => {
  return await axios.get('/cook/getCookById', {
    params: { id }
  })
}

// 根据id删除一道菜名
export const deleteCookById = async (id) => {
  return await axios.get('/cook/deleteCookById', {
    params: { id }
  })
}

export const generateImg = async (msg, size) => {
  return await axios.get('/cook/generateImg', {
    params: { msg, size }
  })
}

// // 图像上传修改
// export const uploadAvatarImg = async (params) => {
//   return await axios.post('/user/uploadAvatarImg', params)
// }

// 发布社区
export const publishCook = async (params) => {
  return await axios.post('common/publishCook', params)
}

// 获取社区里的全部内容
export const getCommonCook = async () => {
  return await axios.get('/common/getCommonCook')
}

// 根据id获取社区中的一条数据
export const getCommonById = async (id) => {
  return await axios.get('/common/getCommonById', {
    params: { id }
  })
}

// 根据id获取社区中一道菜谱的评论
export const getCommentById = async (id) => {
  return await axios.get('/comment/getCommentById', {
    params: { id }
  })
}

// 发表一条评论
export const postComment = async (params) => {
  return await axios.post('comment/postComment', params)
}

// 收藏一个菜品
export const addMyLike = async (params) => {
  return await axios.post('likes/addMyLike', params)
}

// 判断是否收藏过
export const isLike = async (params) => {
  return await axios.post('likes/isLike', params)
}

// 取消收藏
export const deteleLike = async (params) => {
  return await axios.post('likes/deteleLike', params)
}

// 获取我的已发布
export const getMyPublish = async (userId) => {
  return await axios.get('common/getMyPublish', {
    params: { userId }
  })
}

// 获取我的收藏
export const getMyLike = async (userId) => {
  return await axios.get('likes/getMyLike', {
    params: { userId }
  })
}

// 获取我的草稿箱
export const getMyDraft = async (userId) => {
  return await axios.get('common/getMyDraft', {
    params: { userId }
  })
}

// 将草稿状态变为发布状态
export const changePublish = async (id, publishTime) => {
  return await axios.get('common/changePublish', {
    params: { id, publishTime }
  })
}

// 更新完草稿后发布
export const updateCook = async (id, param) => {
  return await axios.post('/common/updateCook', {
    id,
    param // 展开所有要更新的数据字段
  });
};

// 首页获取两个收藏量最高的社区的菜谱
export const getCookByHome = async () => {
  return await axios.get('/common/getCookByHome')
}

// 搜索框中的搜索菜谱
export const getCookByName = async (cookName) => {
  return await axios.get('/common/getCookByName', {
    params: { cookName }
  })
}

// 删除我的食谱
export const deleteMyCook = async (id) => {
  return await axios.get('/common/deleteMyCook', { params: { id } })
}

// 校验用户 token 与 id 是否一致
export const checkUserPermission = async (userId) => {
  return await axios.get('/user/checkUserPermission', { params: { userId } })
}

// 修改用户头像
export const updateAvatar = async (userId, image) => {
  return await axios.post('user/updateAvatar', {
    userId,
    image
  })
}

// 修改昵称
export const updateNickname = async (userId, nickname) => {
  return await axios.post('user/updateNickname', {
    userId,
    nickname
  })
}

// 获取每日推荐
export const getRecommendDaily = async (param) => {
  return await axios.get('/common/getRecommendDaily', {
    params: param
  })
}

